package com.lemo.mp.controller;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.plugins.Page;
import com.lemo.mp.model.Demo;
import com.lemo.mp.model.Lemo;
import com.lemo.mp.service.IDemoService;
import com.lemo.mp.service.ILemoService;

@RestController
@RequestMapping("/lemo")
public class LemoController {

	@Autowired
	private ILemoService ls;
	
	@Autowired
	private IDemoService ds;

	// @RequestMapping("/insert")
	// public boolean insert() {
	// Lemo lemo = new Lemo();
	// lemo.setLname("lemo");
	// lemo.setLbirsteday(new Date());
	// lemo.setLage(28);
	// lemo.setLmonny(new BigDecimal("100.34"));
	// // lemo.setLdesc("");
	// lemo.setLdesc(null);
	// boolean flag = ls.insert(lemo);
	// return flag;
	// }

	// @RequestMapping("/insertOrUpdate")
	// public boolean insertOrUpdate() {
	// Lemo lemo = new Lemo();
	// lemo.setLname("lemo");
	// lemo.setLbirsteday(new Date());
	// lemo.setLage(28);
	// lemo.setLmonny(new BigDecimal("100.34"));
	// // lemo.setLdesc("");
	// lemo.setLdesc(null);
	// boolean flag = ls.insertOrUpdate(lemo);
	// return flag;
	// }

	@RequestMapping("/insertSelective")
	public Lemo insertSelective() {
		
		Lemo lemo = new Lemo();
		lemo.setLname("lemo");
		lemo.setLbirsteday(new Date());
		lemo.setLage(28);
		lemo.setLmonny(new BigDecimal("100.34"));
		// lemo.setLdesc("");
		lemo.setLdesc(null);
		ls.insertSelective(lemo);
		
		ls.deleteAllLemo();
		//检测是否回滚
//		Demo demo = new Demo();
////		demo.setId(UUID.randomUUID().toString());
//		demo.setName(Thread.currentThread().getName());
//		ds.insertSelective(demo);
		
		return lemo;
	}

	@RequestMapping("/insertBatch")
	public ArrayList<Lemo> insertBatch() {
		Lemo lemo = new Lemo();
		lemo.setLname("lemo");
		lemo.setLbirsteday(new Date());
		lemo.setLage(28);
		lemo.setLmonny(new BigDecimal("100.34"));
		// lemo.setLdesc("");
		lemo.setLdesc(null);
		ArrayList<Lemo> entityList = new ArrayList<Lemo>();
		for (int i = 0; i < 10000; i++) {
			entityList.add(lemo);
		}
		ls.insertBatch(entityList);
		return entityList;
	}

	@RequestMapping("/insertOrUpdateSelective")
	public Lemo insertOrUpdateSelective() {
		Lemo lemo = new Lemo();
		lemo.setLid(3L);
		lemo.setLname("lemo1");
		lemo.setLbirsteday(new Date());
		lemo.setLage(28);
		lemo.setLmonny(new BigDecimal("100.35"));
		// lemo.setLdesc("");
		lemo.setLdesc(null);
		ls.insertOrUpdateSelective(lemo);
		return lemo;
	}

	@RequestMapping("/selectByMap")
	public List<Lemo> selectByMap() {
		Map<String, Object> columnMap = new HashMap<String, Object>();
		columnMap.put("lid", 3L);
		List<Lemo> selectByMap = ls.selectByMap(columnMap);
		return selectByMap;
	}

	@RequestMapping("/selectPage")
	public Page<Lemo> selectPage() {
		Page<Lemo> page = new Page<Lemo>(5553, 20);
		return ls.selectPage(page, null);
	}

}
